//
//  UIImageView+WebImage.swift
//  传智微博
//
//  Created by zhoujiming on 2017/2/16.
//  Copyright © 2017年 gmcc. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    /// 隔离SDWebImage设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: urlString
    ///   - placeholderImage: 占位图像
    ///   - isAvatar: 是否头像
    func cz_setImage(urlString: String?, placeholderImage: UIImage?, isAvatar: Bool = false){
    
        guard let urlString = urlString,
            let url = URL(string: urlString) else{
            // 设置占位图像
            image = placeholderImage
            return
        }
        
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil){(image, _, _, _) in
            // 完成回调 -- 判断是否头像
            if isAvatar{
                self.image = image?.cz_avatarImage(size: self.bounds.size)
            }
        }
    }
}
